/*
 * @Author: silence
 * @Date: 2023-07-05 11:14:14
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-10-31 11:19:28
 * @Description: 电站设置Item
 */
import 'package:flutter/material.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';

import '../../../utils/color/ColorUtils.dart';

class PowerStationSetItem extends StatefulWidget {
  final String? title;
  final String? leftImgPath;
  final Widget? rightView;
  final void Function()? tapRightViewFunc;
  final String? subTitle;
  final EdgeInsetsGeometry? padding;
  final int rightViewFlex;

  /// 功能描述
  final String? funcSubcribe;
  const PowerStationSetItem(
      {this.subTitle,
      this.tapRightViewFunc,
      this.title,
      this.leftImgPath,
      this.rightView,
      this.padding,
      this.rightViewFlex = 1,
      this.funcSubcribe,
      super.key});

  @override
  State<PowerStationSetItem> createState() => _PowerStationSetItemState();
}

class _PowerStationSetItemState extends State<PowerStationSetItem> {
  @override
  Widget build(BuildContext context) {
    return contentView();
  }

  contentView() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 20.w),
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  color: ColorUtils.color_divider_line, width: 0.5.w))),
      padding: widget.padding ?? EdgeInsets.symmetric(vertical: 15.w),
      child: Container(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            contentWidget(),
            if (widget.funcSubcribe != null)
              SilText(
                widget.funcSubcribe,
                maxLines: 0,
                color: ColorUtils.color_subtitle,
                fontSize: 12.sp,
                margin: EdgeInsets.only(right: 10.w, top: 8.w),
              ),
          ],
        ),
      ),
    );
  }

  contentWidget() {
    return Row(
      children: [
        /// 左侧图片
        if (widget.leftImgPath != null)
          SilImage(
            widget.leftImgPath,
            width: 24.w,
            height: 24.w,
            margin: EdgeInsets.only(right: 10.w),
          ),

        /// 左边标题
        Expanded(
            flex: 2,
            child: SilText(
              widget.title,
              fontSize: 16.sp,
              color: ColorUtils.color_font_main,
              fontWeight: FontWeight.w500,
              textAlign: TextAlign.left,
              maxLines: 0,
            )),

        // 右侧
        Expanded(
            flex: widget.rightViewFlex,
            child: Container(
              alignment: Alignment.centerRight,
              child: widget.rightView ?? rightView(),
            ))
      ],
    );
  }

  rightView() {
    return SilEmptyButton(
      onTapFunc: widget.tapRightViewFunc,
      useConstrained: true,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Expanded(
              child: SilText(widget.subTitle,
                  fontSize: 14.sp,
                  color: ColorUtils.color_font_minor,
                  textAlign: TextAlign.right)),
          Container(
              margin: EdgeInsets.only(left: 10.w),
              width: 24.w,
              height: 24.w,
              child: SilImage('imgs/personal/list_icon_arrow@3x.png'))
        ],
      ),
    );
  }
}
